<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/4/6
 * Time: 20:55
 */


require_once "../../php/config/database.php";
require_once "userDb.php";

$UserDb=new UserDb();
$userA=$_POST['user'];
$sex=$_POST['sex'];
$tel=$_POST['tel'];
$email=$_POST['email'];
$major=$_POST['major'];
$hobdy=$_POST['hobdy'];
$content=$_POST['content'];
$addtime=time();
$datea=$UserDb->selectStudent($userA);
if($datea==null) {
    $data = $UserDb->add_student($userA, $sex,$tel,$email,$major,$hobdy,$content,$addtime);
    try {
        $result = $data;
        if ($result) {
            $dat = array(
                'message' =>"恭喜你，报名成功，请等待通知",
            );
            echo json_encode($dat);
        } else {
            $dat = array(
                'message' =>"报名失败，请联系负责人",

            );
            echo json_encode($dat);

        }
    }
    catch (Exception $e) {

        // 回滚事务
        // $pdo->rollback();
        echo $e->getMessage();}

}
else
{

    $dat = array(

        'message' =>"你已经报名了，请等待通知...",
        'data'=>$datea,

    );
    echo json_encode($dat);


}

